<style type="text/css">
	.unit_count{text-decoration:underline;padding:0px 8px;cursor: pointer;
	color:#3399FF}
	.layui-form-pane .layui-form-label{width:auto;}
	.layui-form-item{margin-bottom:0px;}
</style>
<div class="fixed-bar">
    <form class="layui-form layui-form-pane fixed-bar-form" action="{:url()}" method="get" id="hisi-table-search">
        <div class="layui-form-item">
        	
	        <div class="layui-inline">
	        	<label class="layui-form-label">材料名称</label>
	            <div class="layui-input-inline">
	                <input type="text" name="material_name" lay-verify="" placeholder="输入材料名称" class="layui-input">
	            </div>
	        </div>
	        
	        <div class="layui-inline">
	        	<label class="layui-form-label">物料SKU</label>
	            <div class="layui-input-inline">
	                <input type="text" name="material_sku" lay-verify="" placeholder="输入材料SKU" class="layui-input">
	            </div>
	        </div>
            <div class="layui-inline">
	        	<label class="layui-form-label">内部SKU</label>
	            <div class="layui-input-inline">
	                <input type="text" name="self_sku" lay-verify="" placeholder="内部SKU" class="layui-input">
	            </div>
	        </div>
            <div class="layui-inline">
	        	<label class="layui-form-label">物料类型</label>
	            <div class="layui-input-inline">
	                {:Form::select('material_type', '', [''=>'请选择',1=>'面料', 2=>'铺料'], '', '')}
	            </div>
	        </div>
            <div class="layui-inline">
	        	<label class="layui-form-label">库存类型</label>
	            <div class="layui-input-inline">
	                {:Form::select('stock_m_type', '', [''=>'请选择']+$stock_m_type, '', '')}
	            </div>
	        </div>
            <div class="layui-inline">
	        	<label class="layui-form-label">货仓</label>
	            <div class="layui-input-inline">
	              {:Form::select('storehouse_id', '', $storehouseKV, '', '')}
	            </div>
	        </div>
            <div class="layui-inline">
	        	<label class="layui-form-label">工厂</label>
	            <div class="layui-input-inline">
	                {:Form::select('factory_id', '', $factoryKV, '', '')}
	            </div>
	        </div>
            <div class="layui-inline">
	        	<label class="layui-form-label">入库时间</label>
	            <div class="layui-input-inline">
	                <input type="text" name="create_date_range" id="create_date_range" readonly="readonly" lay-verify="" placeholder="选择入库时间" class="layui-input">
	            </div>
	        </div>
            <div class="layui-inline removeStat">
                <label class="layui-form-label">采购批号</label>
                <div class="layui-input-inline time_input">
                    <input type="text" name="caigou_number" lay-verify="" placeholder="输入采购批号" class="layui-input">
                </div>
            </div>
	        
	        <div class="layui-inline">
	        	<button type="submit" class="layui-btn" lay-submit="" id="seacher" lay-filter="search">搜索</button>
	        </div>
        </div>
        <input type="hidden" name="action" value="detailList">
        <input type="hidden" name="factoryShow" id="factoryShow" value="">
    </form>
</div>

<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief" style="clear:both;">
    <ul class="layui-tab-title" id="vue_tab_content">
        <li class="layui-this"><a onclick="statCli(1)" href="#">中央库存（<span class="red bold second_count">{$mimoCount}</span>）</a></li>
        <li><a onclick="statCli(2)" href="#">分厂库存（<span class="red bold chird_count">{$otherStockCount}</span>）</a></li>
    </ul>
</div>

<table id="dataTable"></table>

{include file="system@block/layui" /}

<script type="text/html" title="操作按钮模板" id="buttonTpl">
    <a href="{:url('log')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-warm hisi-iframe" hisi-data="{width: '850px', height: '600px'}" title="查看操作日志">使用日志</a>
</script>

<script type="text/html" id="toolbar">
    <div>
        <!--<a href="{:url('add', ['_t' => 3])}" class="layui-btn layui-btn-primary layui-btn-sm layui-icon layui-icon-add-circle-fine hisi-iframe" hisi-data="{width: '500px', height: '500px'}" title="新物料入库">&nbsp;新物料入库</a>&nbsp;-->
        &nbsp;&nbsp;<a data-href="{:url('checkOddments')}?val=2" onclick="openCheckoutWindow()" class="layui-btn layui-btn-sm back">批量出库</a>&nbsp;&nbsp;
	
    </div>
</script>

<script type="text/html" id="updateTimeTpl">
    <div>{{layui.util.toDateString(d.update_time * 1000) }}</div>
</script>

<script type="text/javascript">
    layui.use(['table','jquery', 'tool','laytpl', 'form','laydate'], function() {
        var table = layui.table;
		var $ = layui.jquery;
		var laytpl = layui.laytpl;
		var form = layui.form;
		var laydate = layui.laydate;
		laydate.render({
		    elem: '#create_date_range'
		    ,range: '~'
		    ,theme: 'molv'
		    ,mark: {'{:$today}':''}
	    	,change: function(value, date, endDate){
		    	$('#create_date_range').val(value);
            	$('#layui-laydate1').remove();//关闭面板
            }
		});
		
        var opTable=table.render({
            elem: '#dataTable'
            ,url: '{:url()}?action=detailList&factoryShow=onlyMimo' //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,limits: [20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter', 'exports', 'print']
            ,cols: [[ //表头
                {type:'checkbox', fixed:'left',field:"material_id"}
                ,{field: 'm_type_name', title: '物料类型'}
                ,{field: 'name', title: '物料名称',templet:function(d){return layui.tool.formatMaterialType(d.mInfo.type, '', 2) +'<span class="copy-item">'+d.mInfo.name+'</span>'}, width:160}
                ,{field: 'material_sku', title: '物料SKU',templet:function(d){return '<span class="copy-item">'+d.mInfo.material_sku+'</span>'}}
				,{field: 'self_sku', title: '内部sku'}
				,{field: 'stock', title: '库存总量',templet:function(d){return d.stock}}
				,{field: 'unit_count', title: '总量单位',templet:function(d){return d.mInfo.unit}}
				,{field: 'factory_name', title: '工厂',width:110}
				,{field: 'storehouse_name', title: '货仓'}
				,{field: 'create_time_diff', title: '库龄',templet:function(d){return d.create_time_diff+'天'}}
				,{field: 'caigou_number', title: '采购批号',width:82}
				,{field: 'cloth_num', title: '物料ID'}
				,{field:'supplier',title : '供应商',width:100,templet:function(d){return "<a href='javascript:void(0);' class='supplier' data-supplier='"+d.supplier+"' data-address='"+d.address+"' data-contact='"+d.contact+"'>"+d.mInfo.supplier+"</a>";}}
                ,{field:'model',title : '型号',templet:function(d){return d.mInfo.model;},width:110}
				,{field:'colornum',title : '色号',width:60,templet:function(d){return d.mInfo.colornum;}}
				,{field:'color',title : '颜色',width:60,templet:function(d){return d.mInfo.color;}}	
                ,{field: 'stock_unit_price', title: '库存单价',templet:function(d){return d.mInfo.price;}}
                ,{field: 'amount', title: '库存价值'}
                ,{field: 'update_time', title: '更新时间',templet: '#updateTimeTpl', width:150}
                ,{title: '操作', templet: '#buttonTpl', fixed: 'right',width:90}
            ]]
        });
		
		// 刷新当前页
        window.reloadTable = function () {
            var that = $("#hisi-table-search-optable"),
                arr = that.serializeArray(),
                where = new Array(),
                dataTable = that.attr('data-table') ? that.attr('data-table') : 'dataTable',
                currPage = 1, //$(".layui-laypage-em").next().html()
                options = new Function('return '+ that.attr('hisi-data'))() || {page: {curr:currPage}};
            for(var i in arr) {
                where[arr[i].name] = arr[i].value;
            }

            options.url = that.attr('action');
            options.where = where;

            opTable.reload(options);
            return false;
        }
		
		window.statCli = function(status) {
            $("#factoryShow").val(status==1 ? 'onlyMimo' : 'otherFactorys');
			$(".field-factory_id").find("option").eq(0).attr("selected","selected");
            $("#seacher").click();
        }
		
		// 获取任务列表
		window.openCheckoutWindow = function() {
			if($(".layui-form-checked").size()<=0){
				layer.msg('请选择要操作的数据', {icon: 2,anim: 6});return;
			}
			var checkids='';
			var that = $(document);
			var tableObj = that.attr('data-table') ? that.attr('data-table') : 'dataTable';
			var checkStatus = table.checkStatus(tableObj);
			console.log(checkStatus);
			for(var i=0;i<checkStatus.data.length;i++){
				checkdata=checkStatus.data;
				checkids+=checkdata[i]['material_id']+',';
			}
			
			//data: $('.form-plan').eq(1).serialize(),
			//var content = $('#doneTpl').html();
			var title='批量出库';
			layerStockOutIn = layer.open({
				type: 2
				,area: ['1040px','490px']
				,offset: '200px'
				//,shade:[0.8, '#393D49']
				,anim: parseInt(Math.random()*(6+1),10)
				,skin:'layui-layer-molv'
				,title:title
				,content: "{:url('detailCheckOuts')}?mids="+checkids
			});
		}
    });
	
</script>